package com.liuhong.shoping.controller;


import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.liuhong.shoping.common.ResponseMessage;
import com.liuhong.shoping.dao.RoleInfoMapper;
import com.liuhong.shoping.entity.RoleInfo;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuhong
 * @since 2021-01-11
 */
@RestController
@RequestMapping("/roleInfo")
public class RoleInfoController {
	
	@Autowired
	private RoleInfoMapper roleInfoMapper;
	
	
	/**
	 * 添加角色
	 * @param RoleInfo
	 * @return
	 */
	@PostMapping("addRoleInfo")
	public ResponseMessage addRoleInfo(@RequestBody RoleInfo role)
	{
		try {
			role.setId(UUID.randomUUID().toString());
			role.setCreatedTime(LocalDateTime.now());
			int insertRows = roleInfoMapper.insert(role);
			return ResponseMessage.success(insertRows,"插入成功");
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.fail("插入失败");
		}
	}
	
	/**
	 * @Param{ Map }
	 * 批量删角色
	 */
	@PostMapping("deleteRoleInfoByIds")
    public ResponseMessage deleteRoleInfoByIds(@RequestBody Map<String, Object> map ) 
	{
		try {
			String batchIds = (String)map.get("bathIds");
			String[] split = batchIds.split(",");
			int deleteRows = roleInfoMapper.deleteBatchIds(Arrays.asList(split));
			return ResponseMessage.success(deleteRows,"删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.fail();
		}
    }

}

